home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
bookmarks
/
bookmarksdlg.js
next >
Wrap
Text File
|
2009-12-16
|
5KB
|
191 lines
/*
* bookmarksdlg.js
*
* @author david marteau <marteau.david@free.fr>
* @copyright 2005-2006 Yoono
*/
const CI = Components.interfaces;
const CL = Components.classes;
const RDF = CL['@mozilla.org/rdf/rdf-service;1'].getService(CI.nsIRDFService);
const PREFS = CL['@mozilla.org/preferences-service;1'].getService(CI.nsIPrefBranch);
const PROMPT = CL["@mozilla.org/embedcomp/prompt-service;1"].getService(CI.nsIPromptService);
const BKM_NS_PREFIX = "http://yoono.com/bkm-rdf#";
const kHistoryPref = "extensions.yoono.bookmarks.maxhistory";
var gDialog = {}
var gBkmService = null;
/*!
* Display Archive from rdf content
*/
function displayArchive( name , res )
{
const kLinkRes = RDF.GetResource(BKM_NS_PREFIX+"count");
var archive = gBkmService.archiveFolder;
archive.append( name + ".rdf" );
var urn;
var links = "";
if(archive.exists())
{
var ioSrvc = CL["@mozilla.org/network/io-service;1"].getService(CI.nsIIOService);
var fHandler = ioSrvc.getProtocolHandler("file").QueryInterface(CI.nsIFileProtocolHandler);
urn = fHandler.getURLSpecFromFile(archive);
// Show the number of links in the header
links = gBkmService.dataSource.GetTarget(res,kLinkRes,true);
if(links)
{
try {
links.QueryInterface(CI.nsIRDFLiteral);
links = gDialog.bundle.getFormattedString("archives.numlinks", [links.Value]);
} catch(ex) {
links = "";
}
}
} else {
urn = "rdf:null";
}
gDialog.linkcount.value = links;
gDialog.treebox.setAttribute("datasources",urn);
gDialog.treebox.builder.rebuild();
}
function getSelectedArchive( res )
{
var tree = gDialog.listbox;
var item = tree.contentView.getItemAtIndex(tree.currentIndex);
if(item)
{
var subject = RDF.GetResource(item.id);
var property = RDF.GetResource(BKM_NS_PREFIX+"name");
if(res)
res.value = subject;
var target = gBkmService.dataSource.GetTarget(subject,property,true);
target.QueryInterface(CI.nsIRDFLiteral);
return target.Value;
}
return null;
}
/*!
* Display selected archive
*/
function onSelectArchive( event )
{
var res = { value:null };
var archive = getSelectedArchive(res);
if(archive)
{
displayArchive(archive,res.value);
gDialog.acceptbtn.removeAttribute("disabled");
} else
gDialog.acceptbtn.setAttribute("disabled","true");
}
/*!
* Handle max history change
*/
function onChangeMaxHistory()
{
var item = gDialog.history.selectedItem;
if(item)
{
if(item.value=="custom")
{
var args = {};
window.openDialog('chrome://yoono/content/bookmarks/prompthistory.xul',
'', 'chrome,modal',args);
if(args.cancel)
{
// User has cancelled the dialog
// Restore value from prefs
gDialog.history.value = PREFS.getIntPref(kHistoryPref);
return;
}
// Set custom item
item = setMaxHistory(args.value);
}
// Ask confirmation if we are going to delete
// archives
if(gBkmService.numArchives > Number(item.value)) {
if(!confirm(gDialog.bundle.getString("deletearchives.confirm")))
{
// Restore value from prefs
gDialog.history.value = PREFS.getIntPref(kHistoryPref);
return;
}
}
if(gDialog.history.selectedItem != item)
gDialog.history.value = item.value;
// Set value to pref, service should be notified
PREFS.setIntPref(kHistoryPref,item.value);
}
}
function setMaxHistory( aValue )
{
var item = document.getElementById("custom-history");
item.setAttribute("value",aValue);
item.setAttribute("label",aValue);
return item;
}
function onAcceptDialog()
{
// Ask confirmation for replacing BookMarkFile
if(confirm(gDialog.bundle.getString("replacebookmarks.confirm")))
{
var archive = getSelectedArchive();
gBkmService.restore(archive);
}
}
function onCancelDialog()
{
// Nothing to do
}
function onInitDialog()
{
gBkmService = Components.classes['@yoono.com/bookmarks-restore;1']
.getService().wrappedJSObject;
gDialog.listbox = document.getElementById("backuplistbox");
gDialog.treebox = document.getElementById("bookmarks-tree");
gDialog.history = document.getElementById("maxhistorymenu");
gDialog.bundle = document.getElementById("bundle");
gDialog.acceptbtn = document.getElementById("acceptbtn");
gDialog.linkcount = document.getElementById("linkcount");
var dataSource = gBkmService.dataSource;
gDialog.listbox.database.AddDataSource(dataSource);
gDialog.listbox.builder.rebuild();
var item = setMaxHistory(PREFS.getIntPref(kHistoryPref));
gDialog.history.value = item.value;
}